package com.koron.operation.classes.info.controller;


import com.github.pagehelper.PageInfo;
import com.koron.bean.base.Response;
import com.koron.bean.query.PageQuery;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.operation.classes.info.bean.dto.ClassesDTO;
import com.koron.operation.classes.info.bean.query.ClassesQuery;
import com.koron.operation.classes.info.service.ClassesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.koron.ebs.mybatis.ADOConnection;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 班别方案(Classes)表控制层
 *
 * @author jzp
 * @since 2021-10-19 19:10:14
 */
@Api(tags = "班别方案接口")
@RestController
@RequestMapping("classes")
public class ClassesController {
    /**
     * 服务对象
     */
    @Autowired
    private ClassesService classesService;

    private String getCurrDs() {
        return ThreadLocalContext.get().getCurrDs();
    }

    @ApiOperation(value = "分页")
    @GetMapping("page")
    public Response<PageInfo> page(PageQuery pageQuery, ClassesQuery query) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), classesService, "page", PageInfo.class, pageQuery, query));
    }

    @ApiOperation(value = "根据id查询")
    @GetMapping
    public Response<ClassesDTO> selectOne(@RequestParam String id) {
        return Response.ok(ADOConnection.runTask(getCurrDs(), classesService, "getDtoById", ClassesDTO.class, id));
    }

    @ApiOperation(value = "保存或更新数据")
    @PostMapping
    public Response<String> save(@RequestBody ClassesDTO classesDTO) {
        ADOConnection.runTask(getCurrDs(), classesService, "saveOrUpdateDto", Boolean.class, classesDTO);
        return Response.ok(classesDTO.getId());
    }

    @ApiOperation(value = "删除数据")
    @DeleteMapping
    public Response<String> delete(@RequestParam String id) {
        ADOConnection.runTask(getCurrDs(), classesService, "deleteById", Boolean.class, id);
        return Response.ok();
    }

}
